﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="edit.aspx.cs" Inherits="admin_artcles_edit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="StyleSheet.css" type="text/css" rel="Stylesheet" />
<link href="../../skin/jquery-ui.css" rel="Stylesheet" type="text/css" />
<script type="text/javascript" src="../../js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="../../js/xheditor-1.1.13-zh-cn.min.js"></script>
<script type="text/javascript" src="../../js/jquery-ui.min.js"></script>
<script type="text/javascript">
    var postid;
    $(document).ready(function () {
        $("#ajaxmsg").bind("ajaxSend", function () {
            $(this).html("正在加载...");
            $(this).show(100);
        }).bind("ajaxComplete", function () {
            $(this).hide(100);
        });
        $("#savebtn").click(function () {
            PostAirticle(0);
        });
        postid = getArgs().id;
        GetPost(postid);
        GetClass();
        GetTag();
    });

    function GetClass() {
        $.getJSON("../../Handles/AriticleHandler.ashx", { "act": "getclass" }, function (data) {
            var list;
            $(data).each(function () {
                list += '<option value="' + this.CID + '">' + this.CName + '</option>';
            });
            $("#classlist").html(list);
        });
    }
    function GetTag() {
        $.getJSON("../../Handles/AriticleHandler.ashx", { "act": "gettag" }, function (data) {
            var list;
            $(data).each(function () {
                list += '<option value="' + this.TagID + '">' + this.TagName + '</option>';
            });
            $("#taglist").html(list);
        });
    }
    function GetPost(id) {
        var postdata = { "act": "getpost", "pid": id }
        $.ajax({
            url: "../../Handles/AriticleHandler.ashx",
            type: "post",
            data: postdata,
            dataType: "json",
            success: function (data, textStatus) {
                $("#title").val(data.Title);
                $("#editpanel").val(data.Content);
                $("#classlist").attr("value", data.ClassID);
                $("#taglist").attr("value", data.TagID);
                postid = data.postID;
            }
        });
    }

    function PostAirticle(state) {
        var postdata = { "pid": postid, "act": "edit", "title": $("#title").val(), "content": $("#editpanel").val(), "cid": $("#classlist").val(), "tid": $("#taglist").val(), "state": 1 }
        if ($("#title").val() == "") {
            alert("标题不能为空!");
            return;
        }
        if (postdata.context == "") {
            alert("文章内容不能为空!");
            return;
        }
        $.ajax({
            url: "../../Handles/AriticleHandler.ashx",
            type: "post",
            async: true,
            data: postdata,
            dataType: "json",
            success: function (data, textStatus) {
                var html = "";
                if (data.result) {
                    html = "添加成功";
                    $("#divTip").html(html);
                    $('#divTip').dialog({ buttons: { "确定": function () { $(this).dialog("close"); }, "返回列表": function () { location.href = "list.aspx"; } } });
                } else {
                    html = "添加失败";
                    $("#divTip").html(html);
                    $('#divTip').dialog({ buttons: { "确定": function () { $(this).dialog("close"); } } });
                }
            }
        });
    }
    function getArgs() {
        var args = new Object();
        var query = location.search.substring(1);      // Get query string
        var pairs = query.split("&");                  // Break at ampersand
        for (var i = 0; i < pairs.length; i++) {
            var pos = pairs[i].indexOf('=');           // Look for "name=value"
            if (pos == -1) continue;                   // If not found, skip
            var argname = pairs[i].substring(0, pos); // Extract the name
            var value = pairs[i].substring(pos + 1);     // Extract the value
            value = decodeURIComponent(value);         // Decode it, if needed
            args[argname] = value;                     // Store as a property
        }
        return args;                                   // Return the object
    }
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <div class="editartcle" style="width:720px">
    <br />
    <h2>编辑文章</h2><br />
        <input type="text" id="title" style="border-bottom-style:inset;width:700px;height:35px;Font-Size:20pt" class="titleinput" />
        <br />
    <h2>内容</h2><br />
        <textarea id="editpanel"    class="xheditor {tools:'full',width:'600',height:'300',html5Upload:false,upLinkUrl:'../../Handles/file/saveremoteimg.aspx',upImgUrl:'../../Handles/file/upload.aspx'}" rows="10" cols="80"></textarea>
  <div id="extended">
    <div class="publicbtn">
    <input id="savebtn" type="button" class="bluebutton" value="保存" />&nbsp&nbsp
     </div>
     <div>
     选择文章分类：<br />
         <select id="classlist" style="width:160px">
         </select>
         <br /><br />
         选择文章标签：<br />
         <select id="taglist" style="width:160px">
         </select>
         <br />
     </div>
</div>
</div>
<div id="ajaxmsg">AJAXMSG</div>
<div id="divTip" style="display:none;">
        <span>弹出窗口</span>
</div>
</asp:Content>

